<style scoped lang='less'>
    .selected-search-components {
        .selected-search {
            box-shadow: 0 1px 6px rgba(0, 0, 0, .2);
            height: 200px;
            width: 260px;
            position: relative;
            border-radius: 4px;

            .search-action {
                position: absolute;
                top: 10px;
                left: 10px;
                right: 10px;
            }

            .selected-arr {
                position: absolute;
                top: 50px;
                left: 20px;
                right: 20px;
                bottom: 10px;
                overflow: scroll;
            }
        }
        .select-click {
            border: 1px solid #dddee1;
            border-radius: 4px;
            padding: 0 10px;
            margin-bottom: 10px;
        }
    }
</style>
<template>
    <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="120">
        <Form-item label="通行的起始时间">
            <Row>
                <i-col span="11">
                    <Date-picker type="datetime" placeholder="选择开始日期" @on-change="changeStartDate"></Date-picker>
                </i-col>
            </Row>
        </Form-item>
        <Form-item label="通行的结束时间">
            <Row>
                <i-col span="11">
                    <Date-picker type="datetime" placeholder="选择结束日期" @on-change="changeEndDate"></Date-picker>
                </i-col>
            </Row>
        </Form-item>
        <selectSearch :selectBaseInfo="selectBaseInfo" @post-data="getCompentensData"></selectSearch>
        <div class="selected-search-components">
            <Form-item label="允许通行的访客" prop="">
                <p @click="vistorIsShow ? vistorIsShow=false : vistorIsShow=true" class="select-click">
                    {{vistorName}}</p>
                <div v-if="vistorIsShow" class="selected-search">
                    <div class="selected-arr">
                        <template v-for="(item,index) in vistorPeoPle">
                            <p @click="chooseVResult(item.Id,item.Realname)" class="selected-item">
                                {{item.Realname}}</p>
                        </template>
                    </div>
                </div>
            </Form-item>
        </div>
        <Form-item label="通行的门禁卡ID" prop="peoplecardid">
            <i-input v-model="formValidate.peoplecardid" placeholder="请允许通行的门禁卡ID"></i-input>
        </Form-item>
        <Form-item label="通行的访客卡信息" prop="forvisitorcarid">
            <i-input v-model="formValidate.forvisitorcarid" placeholder="请输入允许通行的访客卡信息"></i-input>
        </Form-item>
        <Form-item label="通行的人脸识别ID" prop="peoplefaceid">
            <i-input v-model="formValidate.peoplefaceid" placeholder="请输入允许通行的人脸识别ID"></i-input>
        </Form-item>
        <Form-item label="通行的车牌号" prop="platenum">
            <i-input v-model="formValidate.platenum" placeholder="请输入允许通行的车牌号"></i-input>
        </Form-item>
        <Form-item label="通行的车卡ID" prop="carcardid">
            <i-input v-model="formValidate.carcardid" placeholder="请输入允许通行的车卡ID"></i-input>
        </Form-item>
        <Form-item label="通行类型" prop="inouttype">
            <i-select v-model="formValidate.inouttype" placeholder="请选择通行类型">
                <i-option value="进">进</i-option>
                <i-option value="出">出</i-option>
            </i-select>
        </Form-item>
        <Form-item label="进来次数" prop="allowedincount">
            <i-input v-model="formValidate.allowedincount" type="number" placeholder="请输入允许的通行（进）次数"></i-input>
        </Form-item>
        <Form-item label="出去次数" prop="allowedoutcount">
            <i-input v-model="formValidate.allowedoutcount" type="number" placeholder="请输入允许的通行（出）次数"></i-input>
        </Form-item>
        <Form-item label="允许通行门区" prop="allowgates">
            <Checkbox-group v-model="formValidate.allowgates" @on-change="checkChange">
                <Checkbox v-for="(item,index) in geteListArr" :value="item.Id" :key="index" :label="item.Gatename">
                    {{item.Gatename}}
                </Checkbox>
            </Checkbox-group>
        </Form-item>
        <Form-item>
            <i-button @click="handleSubmit('formValidate')" type="primary">提交</i-button>
            <i-button type="ghost" @click="jumpPage()" style="margin-left: 8px">返回</i-button>
        </Form-item>
    </i-form>
</template>
<script>
    import apiUtil from '../../assets/utils/api_util';
    import baseUtil from '../../assets/utils/base-util';
    import selectSearch from '../../components/selectSearch';

    export default {
        data() {
            return {
                formValidate: {
                    //添加字段
                    startdate: '',
                    enddate: '',
                    peoplecardid: '',
                    forvisitorcarid: '',
                    peoplefaceid: '',
                    platenum: '',
                    carcardid: '',
                    inouttype: '',
                    allowedincount: '',
                    allowedoutcount: '',
                    allowgates: '',
                },
                ruleValidate: {},
                fortypeArr: [],
                //选择取件员人
                selectBaseInfo: {
                    "title": '选择允许通行的人员',
                    "placeholder": '请输入姓名',
                    "postUrl": apiUtil.urls.userList,
                    'postType': 'user',
                },
                reqpeopleDept: '',
                //门区列表
                geteListArr: [],
                checkGateArr: [],
                //访客
                vistorPeoPle: [],
                vistorName: "请选择访客",
                vistorId: "",
                vistorIsShow: false,
            }
        },
        components: {
            selectSearch
        },
        mounted: function () {
            this.getGateList();
            this.getVistorData();
        },

        methods: {
            //跳转
            jumpPage: function (id, url) {
                this.$router.back(-1)

            },
            //获取选择搜索组件传来结果数据
            getCompentensData: function (value) {
                this.reqpeopleDept = value;
            },
            changeStartDate: function (date) {
                console.log(date);
                this.formValidate.startdate = date;
            },
            changeEndDate: function (date) {
                console.log(date);
                this.formValidate.enddate = date;
            },
            checkChange: function (data) {
                console.log('多选值:', data);

                // this.checkGateArr.push(data[0]);
                console.log('gateArr:', this.formValidate.allowgates)

            },
            getVistorData: function () {
                let that = this;

                let para = {
                    curPage: 1,
                    pageSize: 300,
                };
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.VistorPeopleList, para, function (res) {
                    that.$Loading.finish();

                    that.vistorPeoPle = res.Msg.Arrays;

                    console.log('tableData:', res)
                });

            },
            //获取门区信息
            getGateList() {
                let that = this;

                let para = {};
                let params = that.$qs.stringify(para);

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.GateServerList, para, function (res) {
                    that.$Loading.finish();

                    that.geteListArr = res.Msg;

                });
            },
            chooseVResult: function (id, name) {
                this.vistorName = name;
                this.vistorId = id;
                this.vistorIsShow = false;

            },
            //添加
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;
                this.$refs[name].validate((valid) => {
                    that.addData(model);
                })
            },

            addData: function (model) {
                let that = this;

                model.forpeopleid = this.reqpeopleDept.resultId;   //允许通行的人员ID
                model.forvisitorid = this.vistorId;  //允许通行的访客ID

                let params = that.$qs.stringify(model);
                this.$Loading.start();

                apiUtil.post(that, apiUtil.urls.AddAccessInfo, params, function (res) {
                    that.$Loading.finish();

                    that.$Modal.confirm({
                        title: '操作成功',
                        content: '请选择下一步操作',
                        okText: '继续添加',
                        cancelText: '返回列表',
                        onOk: () => {
                        },
                        onCancel: () => {
                            baseUtil.pageJump(that, '', 'AccessList')
                        }
                    });
                });
            },


        }
    }
</script>
